<?php

/**
 * 
 * ClientEngage: ClientEngage Visitor Voice (http://www.clientengage.com)
 * Copyright 2012, ClientEngage (http://www.clientengage.com)
 *
 * You must have purchased a valid license from CodeCanyon in order to have 
 * the permission to use this file.
 * 
 * You may only use this file according to the respective licensing terms 
 * you agreed to when purchasing this item on CodeCanyon.
 * 
 * 
 * 
 *
 * @author          ClientEngage <contact@clientengage.com>
 * @copyright       Copyright 2013, ClientEngage (http://www.clientengage.com)
 * @link            http://www.clientengage.com ClientEngage
 * @since           ClientEngage - Visitor Voice v 1.0
 * 
 */

/**
 * Layout helper
 */
class LayoutHelper extends AppHelper
{

    public $helpers = array(
        'Html' => array('className' => 'AppHtml'),
        'Text',
        'Time' => array('className' => 'AppTime'),
        'Number' => array('className' => 'AppNumber'),
        'Form' => array('className' => 'AppForm'));

    function __construct(View $view, $settings = array())
    {
        parent::__construct($view, $settings);
    }

    /**
     * Returns the verbose version of a boolean value
     * @param boolean $bool The boolean value to be rendered verbose
     * @return string Yes or No (in the respective locale)
     */
    public function boolYesNo($bool = null)
    {
        if ($bool === null)
            return '<span class="label">' . __('N/A') . '</span>';
        if ($bool === true)
            return '<span class="label label-success">' . __('Yes') . '</span>';
        else
            return '<span class="label label-important">' . __('No') . '</span>';
    }

    /**
     * Syste,-wide default display for DateTime values
     * @param string $time The DateTime to be rendered
     * @return string Rendered display version of the DateTime
     */
    public function displayTimeDefault($time = null)
    {
        if ($time === null)
            return '';
        else
            return '<span data-original-title="' . $this->Time->timeAgoInWords($time) . '" data-rel="tooltip">' . $this->Time->niceShort($time) . '</span>';
    }

    /**
     * 
     * @param string $text The string to be rendered in a help icon
     * @return string The HTML markup of the help icon & tooltip
     */
    public function renderHelpIcon($text = '')
    {
        $out = ' <i class="ico-information" data-rel="tooltip" tabindex="100" data-original-title="' . $text . '"></i>';
        return $out;
    }

    public function renderUserAgent($useragent = null, $showTooltip = true)
    {
        App::import('Vendor', 'PHPUserAgent', array('file' => 'php-user-agent' . DS . 'lib' . DS . 'phpUserAgent.php'));

        $phpUserAgent = new phpUserAgent($useragent);
        $browserData = $phpUserAgent->toArray();

        if (empty($browserData))
            return $useragent;
        else
        {
            $toolTip = '';
            if ($showTooltip)
                $toolTip = ' data-original-title="' . $useragent . '" rel="popover" data-rel="tooltip"  style="display: inline-block; cursor: help;"';
            $out = '<div' . $toolTip . '>';
            $out .= __('Browser') . ': ' . ucfirst($browserData['browser_name']) . ' (version: ' . $browserData['browser_version'] . ') | ';
            $out .= __('Operating System') . ': ' . ucfirst($browserData['operating_system']);
            $out .= '</div>';
            return $out;
        }
    }

}